//
//  TopUserInfoView.swift
//  MyTest
//
//  Created by guanzhongwang on 2021/5/10.
//

import UIKit

class TopUserInfoView: UIView {
    init() {
        super.init(frame: CGRect.zero)
        
        let headImage = UIImageView()
        headImage.backgroundColor = .red
        addSubview(headImage)
        headImage.snp.makeConstraints({
            $0.left.top.equalTo(15)
            $0.width.height.equalTo(50)
        })
        headImage.layer.cornerRadius = 25
        headImage.layer.borderWidth = 0.5
        headImage.layer.borderColor = B999_TITLE_COLOR.cgColor
        
        let arrow = UIImageView()
        let image = UIImage(named: "arrowright")?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
        arrow.image = image
        arrow.tintColor = .lightGray
        
        let infobtn = UIButton(type: .custom)
        infobtn.setTitle("个人主页", for: .normal)
        infobtn.titleLabel?.font = Font_Size_12
        infobtn.setTitleColor(B999_TITLE_COLOR, for: .normal)
        infobtn.addTarget(self, action: #selector(userInfo), for: .touchUpInside)
        addSubview(infobtn)
        addSubview(arrow)
        arrow.snp.makeConstraints({
            $0.right.equalToSuperview().inset(15)
            $0.centerY.equalTo(headImage)
            $0.size.equalTo(image!.size)
        })
        
        let nameLabel = UILabel()
        nameLabel.text = "这条路有点长"
        addSubview(nameLabel)
        nameLabel.textColor = B000_COLOR
        nameLabel.font = getLabelFont(18,blod: true)
        nameLabel.snp.makeConstraints({
            $0.left.equalTo(headImage.snp.right).offset(10)
            $0.centerY.equalTo(headImage)
        })
        infobtn.setContentHuggingPriority(UILayoutPriority.defaultHigh, for: .horizontal)
        infobtn.snp.makeConstraints({
            $0.right.equalTo(arrow.snp.left).offset(3)
            $0.centerY.equalTo(headImage)
            $0.left.equalTo(nameLabel.snp.right).offset(5)
            
        })
        var temp:UIView?
        let names = ["头条","获赞","粉丝","关注"]
        for i in 0...3 {
            let sv = UIView()
            sv.tag = 1000+i
            sv.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(infoTap)))
            addSubview(sv)
            sv.snp.makeConstraints({
                if temp == nil{
                    $0.leading.equalTo(15)
                }else{
                    $0.leading.equalTo(temp!.snp.trailing)
                    $0.width.equalTo(temp!)
                }
                
                $0.top.equalTo(headImage.snp.bottom).offset(10)
                if i == 3{
                    $0.trailing.equalToSuperview().inset(15)
                    $0.bottom.equalTo(0)
                }
            })
            let nums = UILabel()
            nums.textColor = B000_COLOR
            nums.font = Font_Size_14
            nums.text = "999"
            sv.addSubview(nums)
            nums.snp.makeConstraints({
                $0.top.equalTo(15)
                $0.centerX.equalToSuperview()
            })
            let text = UILabel()
            text.textColor = B999_TITLE_COLOR
            text.font = Font_Size_12
            text.text = names[i]
            sv.addSubview(text)
            text.snp.makeConstraints({
                $0.centerX.equalTo(nums)
                $0.top.equalTo(nums.snp.bottom).offset(5)
                $0.bottom.equalToSuperview().inset(10)
            })
            temp = sv
        }
    }
    @objc func infoTap(tap:UITapGestureRecognizer){
        switch tap.view?.tag {
        case 1000:
            break
        case 1001:
            PraiseAlertView.show()
        case 1002:
            let vc = fatherViewController() as? CommonViewController
            vc?.pushViewController(FansViewController(), animated: true)
            vc?.hidesBottomBarWhenPushed = false
        case 1003:
            break
        default:
            break
        }
        if tap.view?.tag == 1001{
        }
        
    }
    @objc func userInfo() {
        
    }
    func updateUserInfo()  {
        
    }
    required init?(coder: NSCoder) {
        fatalError("TopUserInfoView:fatalError")
    }

}
